// src/pages/room/widgets/message/index.tsx
import { MsgType } from "@enums/room";
import Normal from "@pages/room/widgets/normal";
import Reminder from "@pages/room/widgets/reminder";
import Patient from "@pages/room/widgets/patient";
import Say_patient from "@pages/room/widgets/say_patient";
import Say_doctor from "@pages/room/widgets/say_doctor";
import React from "react";
import {useTypedSelector} from "@store/index";
import {selectAuth} from "@store/slices/authSlice";
import Evaluate from "@pages/room/evaluate";
import Prescript from "@pages/room/widgets/prescript";
import EvaluateComplete from "@pages/room/widgets/evaluate_c";

interface Props {
    messages: Message[];
    orderId?: string;
    docId?: string;
    updateEvaluate: (score: number) => void;
}

export default function Message({ messages, orderId, docId ,updateEvaluate }: Props) {
    // 获取用户 id
    const { id } = useTypedSelector(selectAuth);
    return (
        <>
            {messages.map((message) => {
                switch (message.msgType) {
                    case MsgType.CardPat:
                        return <Patient key={message.id} consultRecord={message.msg.consultRecord!} />;
                    case MsgType.Notify:
                        return <Normal key={message.id} msg={message.msg.content!} />;
                    case MsgType.NotifyTip:
                        return <Reminder key={message.id} msg={message.msg.content!} />;
                    case MsgType.CardPre:
                        return <Prescript key={message.id} prescription={message.msg.prescription!} />
                    case MsgType.MsgText:
                        return message.from === id ? (
                            <Say_patient key={message.id} message={message} />
                        ) : (
                            <Say_doctor key={message.id} message={message} />
                        );
                    case MsgType.MsgImage:
                        return message.from === id ? (
                            <Say_patient key={message.id} message={message} />
                        ) : (
                            <Say_doctor key={message.id} message={message} />
                        );
                    case MsgType.CardEvaForm:
                        return <Evaluate key={message.id}  orderId={orderId} docId={docId} updateEvaluate={updateEvaluate}/>;
                    // 已评价
                    case MsgType.CardEva:
                        return <EvaluateComplete key={message.id} score={message.msg.evaluateDoc!.score} />;
                    default:
                        return null;
                }
            })}
        </>
    );
}